Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./year2.RDS")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2021-06-30"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2021-06-30"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 323)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 11.52693 11.56602 11.60474 11.64309 11.68109 11.71875 11.75606 11.79303
## [9] 11.82969 11.86602 11.90205 11.93778 11.97321 12.00834 12.04318 12.07769
## [17] 12.11188 12.14573 12.17922 12.21235 12.24511 12.27748 12.30966 12.34183
## [25] 12.37390 12.40580 12.43747 12.46882 12.49979 12.53030 12.56028 12.58966
## [33] 12.61836 12.64632 12.67467 12.70414 12.73404 12.76367 12.79233 12.81932
## [41] 12.84394 12.86837 12.89468 12.92207 12.94971 12.97680 13.00252 13.02606
## [49] 13.04659 13.06331 13.07820 13.09352 13.10886 13.12381 13.13797 13.15092
## [57] 13.16227 13.17160 13.17851 13.18259 13.18343 13.18063 13.17356 13.16233
## [65] 13.14766 13.13026 13.11085 13.09015 13.06886 13.04771 13.02741 13.00294
## [73] 12.97062 12.93321 12.89343 12.85404 12.81779 12.78740 12.75868 12.72613
## [81] 12.69061 12.65295 12.61400 12.57460 12.53560 12.49782 12.46213 12.42935
## [89] 12.40034 12.37593 12.35450 12.33385 12.31404 12.29509 12.27705 12.25996
## [97] 12.24384 12.22874 12.21469 12.20222 12.19168 12.18286 12.17554 12.16949
## [105] 12.16449 12.16033 12.15678 12.15362 12.15064 12.14760 12.14430 12.14207
## [113] 12.14199 12.14347 12.14591 12.14871 12.15128 12.15302 12.15490 12.15808
## [121] 12.16230 12.16727 12.17274 12.17842 12.18404 12.18932 12.19400 12.19917
## [129] 12.20588 12.21380 12.22260 12.23195 12.24152 12.25097 12.25997 12.26819
## [137] 12.27531 12.28098 12.28488 12.28667 12.28647 12.28467 12.28163 12.27774
## [145] 12.27336 12.26888 12.26466 12.26109 12.25854 12.25738 12.25799 12.26075
## [153] 12.26603 12.26968 12.26879 12.26560 12.26233 12.26122 12.26451 12.27443
## [161] 12.28940 12.30619 12.32447 12.34397 12.36438 12.38540 12.40674 12.42810
## [169] 12.44918 12.47340 12.50381 12.53961 12.57999 12.62412 12.67122 12.72045
## [177] 12.77100 12.82207 12.87284 12.92251 12.97025 13.01525 13.05671 13.09381
## [185] 13.12574 13.15168 13.17083 13.18237 13.18901 13.19389 13.19688 13.19781
## [193] 13.19655 13.19294 13.18683 13.17808 13.16653 13.14741 13.11810 13.08172
## [201] 13.04136 13.00013 12.96113 12.92747 12.89381 12.85350 12.80773 12.75768
## [209] 12.70452 12.64943 12.59358 12.53816 12.48433 12.43329 12.38620 12.34424
## [217] 12.30393 12.26148 12.21759 12.17294 12.12823 12.08416 12.04142 12.00070
## [225] 11.96270 11.92583 11.88823 11.85027 11.81228 11.77460 11.73757 11.70154
## [233] 11.66685 11.63384 11.60286 11.57424 11.54832 11.52291 11.49627 11.46944
## [241] 11.44346 11.41936 11.39818 11.38095 11.36638 11.35265 11.34002 11.32874
## [249] 11.31908 11.31130 11.30566 11.30242 11.30183 11.30425 11.30967 11.31781
## [257] 11.32842 11.34123 11.35597 11.37237 11.39017 11.40909 11.42888 11.44927
## [265] 11.46998 11.49633 11.53202 11.57439 11.62079 11.66855 11.71501 11.75752
## [273] 11.79341 11.82003 11.84401 11.87244 11.90325 11.93441 11.96389 11.98963
## [281] 12.00960 12.02419 12.03557 12.04433 12.05107 12.05638 12.06086 12.06509
## [289] 12.06969 12.07524 12.08233 12.09157 12.10354 12.11657 12.12873 12.14025
## [297] 12.15136 12.16230 12.17331 12.18461 12.19645 12.20905 12.22196 12.23460
## [305] 12.24703 12.25931 12.27150 12.28366 12.29585 12.30813 12.32055 12.33317
## [313] 12.34606 12.35927 12.37286 12.38689 12.40159 12.41705 12.43314 12.44969
## [321] 12.46656 12.48360 12.50066
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./site_objects/wrf_a_year2.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 323)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 10.71816 10.81038 10.90075 10.98924 11.07586 11.16057 11.24337 11.32424
## [9] 11.40317 11.48014 11.55514 11.62815 11.69916 11.76814 11.83510 11.90009
## [17] 11.96313 12.02427 12.08353 12.14096 12.19659 12.25046 12.30229 12.35183
## [25] 12.39918 12.44443 12.48768 12.52902 12.56854 12.60633 12.64249 12.67712
## [33] 12.71030 12.74213 12.77192 12.79917 12.82424 12.84749 12.86928 12.88997
## [41] 12.90991 12.92749 12.94125 12.95186 12.95998 12.96625 12.97134 12.97590
## [49] 12.98060 12.98607 12.99070 12.99267 12.99240 12.99030 12.98677 12.98223
## [57] 12.97708 12.97173 12.96659 12.96207 12.95858 12.95653 12.95540 12.95431
## [65] 12.95308 12.95157 12.94963 12.94711 12.94384 12.93967 12.93445 12.92907
## [73] 12.92418 12.91930 12.91391 12.90754 12.89967 12.88982 12.87825 12.86562
## [81] 12.85204 12.83763 12.82251 12.80678 12.79057 12.77399 12.75715 12.74016
## [89] 12.72315 12.70622 12.68977 12.67389 12.65822 12.64240 12.62605 12.60883
## [97] 12.59036 12.57028 12.54824 12.52240 12.49177 12.45727 12.41980 12.38029
## [105] 12.33963 12.29874 12.25853 12.21992 12.18381 12.15112 12.12276 12.09083
## [113] 12.04969 12.00367 11.95706 11.91419 11.87936 11.85688 11.84199 11.82738
## [121] 11.81354 11.80093 11.79005 11.78136 11.77534 11.77248 11.77325 11.77864
## [129] 11.78884 11.80312 11.82075 11.84101 11.86318 11.88652 11.91030 11.93381
## [137] 11.95632 11.97709 11.99541 12.01525 12.04055 12.07049 12.10426 12.14106
## [145] 12.18008 12.22049 12.26150 12.30229 12.34206 12.37998 12.41526 12.44708
## [153] 12.47463 12.49866 12.52089 12.54196 12.56254 12.58327 12.60481 12.62781
## [161] 12.64994 12.66894 12.68557 12.70057 12.71471 12.72874 12.74341 12.75949
## [169] 12.77773 12.79892 12.82307 12.84978 12.87862 12.90918 12.94104 12.97378
## [177] 13.00698 13.04023 13.07312 13.10521 13.13611 13.16538 13.19262 13.21740
## [185] 13.23931 13.25793 13.27284 13.28363 13.29205 13.29992 13.30690 13.31266
## [193] 13.31687 13.31920 13.31932 13.31690 13.31161 13.30291 13.29087 13.27609
## [201] 13.25918 13.24072 13.22131 13.20156 13.18000 13.15503 13.12706 13.09649
## [209] 13.06371 13.02914 12.99318 12.95622 12.91867 12.88093 12.84340 12.80649
## [217] 12.76634 12.71990 12.66876 12.61454 12.55884 12.50326 12.44941 12.39889
## [225] 12.35330 12.30935 12.26307 12.21506 12.16590 12.11620 12.06656 12.01758
## [233] 11.96984 11.92396 11.88052 11.84013 11.80337 11.76843 11.73340 11.69881
## [241] 11.66517 11.63303 11.60288 11.57526 11.54969 11.52539 11.50245 11.48097
## [249] 11.46104 11.44275 11.42618 11.41144 11.39861 11.38736 11.37735 11.36864
## [257] 11.36132 11.35547 11.35115 11.34844 11.34742 11.34817 11.35075 11.35526
## [265] 11.36175 11.37155 11.38534 11.40226 11.42147 11.44209 11.46329 11.48420
## [273] 11.50396 11.52173 11.54204 11.56853 11.59899 11.63121 11.66300 11.69213
## [281] 11.71642 11.73822 11.76124 11.78529 11.81017 11.83568 11.86162 11.88778
## [289] 11.91398 11.94000 11.96566 11.99074 12.01506 12.03900 12.06310 12.08733
## [297] 12.11166 12.13607 12.16053 12.18502 12.20952 12.23399 12.25845 12.28290
## [305] 12.30737 12.33185 12.35638 12.38095 12.40559 12.43030 12.45511 12.48001
## [313] 12.50503 12.53017 12.55546 12.58090 12.60657 12.63251 12.65869 12.68506
## [321] 12.71159 12.73824 12.76496
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./site_objects/wrf_b_year2.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 323)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 10.82866 10.89297 10.95610 11.01803 11.07873 11.13816 11.19631 11.25314
## [9] 11.30863 11.36274 11.41544 11.46671 11.51652 11.56489 11.61191 11.65762
## [17] 11.70204 11.74523 11.78721 11.82802 11.86771 11.90632 11.94321 11.97788
## [25] 12.01055 12.04144 12.07078 12.09877 12.12563 12.15159 12.17686 12.20166
## [33] 12.22620 12.25072 12.27416 12.29568 12.31576 12.33491 12.35363 12.37241
## [41] 12.39175 12.41214 12.43344 12.45518 12.47692 12.49820 12.51856 12.53756
## [49] 12.55474 12.56964 12.58321 12.59653 12.60944 12.62173 12.63323 12.64374
## [57] 12.65306 12.66103 12.66744 12.67210 12.67483 12.67544 12.67367 12.66964
## [65] 12.66373 12.65636 12.64789 12.63873 12.62926 12.61988 12.61097 12.60129
## [73] 12.58962 12.57636 12.56195 12.54681 12.53135 12.51599 12.49885 12.47820
## [81] 12.45468 12.42895 12.40166 12.37346 12.34501 12.31695 12.28995 12.26464
## [89] 12.24169 12.22175 12.20234 12.18105 12.15862 12.13579 12.11329 12.09187
## [97] 12.07225 12.05519 12.04142 12.03082 12.02252 12.01615 12.01133 12.00767
## [105] 12.00481 12.00235 11.99993 11.99716 11.99367 11.98907 11.98299 11.97710
## [113] 11.97295 11.96992 11.96740 11.96478 11.96146 11.95682 11.95181 11.94769
## [121] 11.94432 11.94156 11.93927 11.93731 11.93555 11.93385 11.93207 11.93016
## [129] 11.92815 11.92601 11.92373 11.92128 11.91865 11.91581 11.91273 11.90940
## [137] 11.90579 11.90188 11.89766 11.89137 11.88173 11.86945 11.85521 11.83970
## [145] 11.82363 11.80767 11.79253 11.77890 11.76747 11.75892 11.75396 11.75328
## [153] 11.75757 11.76465 11.77217 11.78051 11.79006 11.80124 11.81441 11.83000
## [161] 11.84875 11.87075 11.89533 11.92183 11.94957 11.97789 12.00613 12.03363
## [169] 12.05971 12.08793 12.12184 12.16072 12.20388 12.25062 12.30024 12.35204
## [177] 12.40532 12.45938 12.51351 12.56703 12.61923 12.66941 12.71687 12.76091
## [185] 12.80083 12.83594 12.86552 12.88889 12.90917 12.92953 12.94932 12.96787
## [193] 12.98452 12.99863 13.00954 13.01659 13.01911 13.01603 13.00752 12.99487
## [201] 12.97936 12.96227 12.94488 12.92847 12.90985 12.88557 12.85646 12.82339
## [209] 12.78721 12.74877 12.70892 12.66851 12.62839 12.58942 12.55246 12.51834
## [217] 12.48145 12.43696 12.38694 12.33343 12.27851 12.22424 12.17267 12.12586
## [225] 12.08588 12.04813 12.00722 11.96406 11.91956 11.87463 11.83016 11.78706
## [233] 11.74625 11.70861 11.67507 11.64652 11.62387 11.60707 11.59478 11.58598
## [241] 11.57966 11.57480 11.57038 11.56540 11.56489 11.57305 11.58763 11.60634
## [249] 11.62690 11.64705 11.66450 11.67698 11.68222 11.68393 11.68718 11.69165
## [257] 11.69703 11.70304 11.70936 11.71569 11.72174 11.72719 11.73176 11.73513
## [265] 11.73700 11.73458 11.72646 11.71442 11.70026 11.68575 11.67269 11.66285
## [273] 11.65802 11.65999 11.66454 11.66701 11.66857 11.67036 11.67354 11.67924
## [281] 11.68862 11.70225 11.71943 11.73948 11.76172 11.78543 11.80993 11.83452
## [289] 11.85852 11.88122 11.90194 11.91997 11.93463 11.94793 11.96216 11.97702
## [297] 11.99224 12.00753 12.02259 12.03714 12.05090 12.06358 12.07572 12.08805
## [305] 12.10047 12.11292 12.12533 12.13762 12.14972 12.16157 12.17308 12.18420
## [313] 12.19484 12.20493 12.21440 12.22319 12.23103 12.23786 12.24384 12.24914
## [321] 12.25393 12.25839 12.26268
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./site_objects/wrf_c_year2.rda")
keeping in case
#save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
#save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
#save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
#save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
#save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
#save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
#save(both_ymina, file = "./plotly_objs/both_ymina.rda")
#save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
#save(both_yminb, file = "./plotly_objs/both_yminb.rda")
#save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
#save(both_yminc, file = "./plotly_objs/both_yminc.rda")
#save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")